package com.zhq.blog.core.domain.other;

import javax.persistence.Entity;
import javax.persistence.PrePersist;

import com.zhq.blog.core.domain.BasePersistentDomain;

/**
 * @title:DetailsOfFunds.java
 * @package com.zhq.blog.core.domain.other
 * @author 张恒强
 * @date 2014年12月26日 上午10:33:01
 * @version V1.0
 * 玩家资金明细
 */
@Entity
public class DetailsOfFunds extends BasePersistentDomain<DetailsOfFundsRepository>{
	
	public enum DetailType{
		//勿轻易改变顺序
		STORE_TO_BANK("存入银行"),TAKE_OUT_FROM_BANK("银行取出"),AUTO_BET("自动押注"),
		MANUAL_BET("手工押注"),BONUS("奖金"),RECHARGE("兑换奖品"),EXCHANGE("卡密充值"),
		GIVE_BACK("退还投注");
		
		public String description;
		
		DetailType(final String description){
			this.description = description;
		}
	}
	//////////////////////必填项开始//////////////////////////////////
	private long userId;//玩家ID
	
	private DetailType type;//明细类型
	
	private long beforeChange; // 变化前
	
	private long afterChange; //变化后
	
	private long Changes;//变化金额 减少为负 增加为正
	
	private String description;//描述
	/////////////////////必填项结束//////////////////////////////////////
	
	///类型为押注 、返奖、返投注时必填项 
	
	private String gameName; // 押注游戏名称
	
	private long gamePeriod; // 押注游戏期数
	
	private int betNumber; // 押注的号码
	
	
	//类型为兑换奖品时必填项
	private String prizeId;// 奖品ID
	
	private String prizeName;//兑换的奖品名称
	
	//类型为卡密充值时必填项
	private long cardId;//充值卡ID
	
	
	
	//返还奖金构造器
	public DetailsOfFunds(long userId, DetailType type, long beforeChange,
			long afterChange, long changes, String gameName, long gamePeriod,
			int betNumber) {
		super();
		this.userId = userId;
		this.type = type;
		this.beforeChange = beforeChange;
		this.afterChange = afterChange;
		Changes = changes;
		this.gameName = gameName;
		this.gamePeriod = gamePeriod;
		this.betNumber = betNumber;
	}

	public DetailsOfFunds() {
		super();
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}

	public DetailType getType() {
		return type;
	}

	public void setType(DetailType type) {
		this.type = type;
	}

	public long getBeforeChange() {
		return beforeChange;
	}

	public void setBeforeChange(long beforeChange) {
		this.beforeChange = beforeChange;
	}

	public long getAfterChange() {
		return afterChange;
	}

	public void setAfterChange(long afterChange) {
		this.afterChange = afterChange;
	}

	public long getChanges() {
		return Changes;
	}

	public void setChanges(long changes) {
		Changes = changes;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getGameName() {
		return gameName;
	}

	public void setGameName(String gameName) {
		this.gameName = gameName;
	}

	public long getGamePeriod() {
		return gamePeriod;
	}

	public void setGamePeriod(int gamePeriod) {
		this.gamePeriod = gamePeriod;
	}

	public int getBetNumber() {
		return betNumber;
	}

	public void setBetNumber(int betNumber) {
		this.betNumber = betNumber;
	}

	public String getPrizeId() {
		return prizeId;
	}

	public void setPrizeId(String prizeId) {
		this.prizeId = prizeId;
	}

	public String getPrizeName() {
		return prizeName;
	}

	public void setPrizeName(String prizeName) {
		this.prizeName = prizeName;
	}

	
	public long getCardId() {
		return cardId;
	}

	public void setCardId(long cardId) {
		this.cardId = cardId;
	}

	@PrePersist
	public void generateDescription(){
		StringBuffer buffer = new StringBuffer("");
		switch (type.ordinal()){
		case 0://存入银行
			buffer.append("存入银行"+Math.abs(Changes)+"金币");
			break;
		case 1://银行取出
			buffer.append("从银行取出"+Math.abs(Changes)+"金币");
			break;
		case 2://自动押注
			buffer.append("自动押注"+gameName+"游戏"+gamePeriod+"期"+betNumber+"号,消耗"+Math.abs(Changes)+"金币");
			break;
		case 3://手工押注
			buffer.append("手工押注"+gameName+"游戏"+gamePeriod+"期"+betNumber+"号,消耗"+Math.abs(Changes)+"金币");
			break;
		case 4://返奖
			buffer.append("在"+gameName+"游戏的"+gamePeriod+"期,押中"+betNumber+"号,奖励"+Math.abs(Changes)+"金币");
			break;
		case 5://兑换奖品
			buffer.append("兑换了"+prizeName+"奖品,消耗掉"+Math.abs(Changes)+"金币");
			break;
		case 6://卡密充值
			buffer.append("充值"+Math.abs(Changes)+"金币");
			break;
		case 7://退还投注
			buffer.append("由于系统故障原因,"+gameName+"游戏的"+gamePeriod+"期未能开奖,退还您在该期投"+betNumber+"号的押注:"+Math.abs(Changes)+"金币.\n\n\n该邮件为系统自动发送,请勿回复!!");
			break;
		}
		this.description = buffer.toString();
	}
	
	
}
